import {
  getPage
} from '../../utils/config';
import api from '../../utils/api';
import {
  http,
  $toast
} from '../../utils/utils';
import wxApi from '../../utils/wxApi';
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    shopdone: false,
    shopabnor: false,
    loadmore: false,
    showDetails:true
  },
  kjdetailClose(e){
    this.setData({
      showDetails:false
    })
  },
  editadmin(){
    wxApi.navigateTo(getPage.editadmin);
  },
  modify(e) {
    const data = e.currentTarget.dataset || e.target.dataset;
    if (data.id) {
      wxApi.navigateTo(getPage.editadmin, {
        id: data.id
      });
    }
  },
  /**
   * 收货地址 -- 网路请求
   */
  getcontacters(callback, a = false) {
    http.post(api.default, {
      data: {
        action: 'getadmins',
        shopId:this.data.shopid
      }
    }, a).then((res) => {

      const data = res.data.data;
      const pages = 1;

      //记录数据
      this.setData({
        shopPages: pages,
        shopabnor: data.pages == 0 ? true : false,
      });
      callback && callback(data);
      this.setData({
        shopdone: pages == 1 ? true : false,
      })
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {



    //判断是否登录
    app.getLogin().then((res) => {
      console.log(res.data);
      this.setData({
        logged: res.code,
        userId: res.data.user.user_id,
        shopid:res.data.shop.ShopId,
        picurl:res.data.shop.picurl,
        ShopName:res.data.shop.ShopName
      });
      //获取收货地址列表
      this.getcontacters((res) => {
        console.log(res);
        this.setData({
          list: res.list
        });
      });
    }).catch((res) => {
      this.setData({
        logged: res
      });
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  onShareAppMessage: function(res) {
    let {ShopName,shopid,picurl} = this.data;
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res);
    }
    return {
      title: `${ShopName}邀请您加入成为子账户`,
      imageUrl: api.imageCdn + picurl,
      path: `/subPackages/pages/yaoqinguser/yaoqinguser?shopName=${ShopName}&shopid=${shopid}&img=${api.imageCdn + picurl}`,
    }
  },

})